package com.moli.lumpSugar.user.dao;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


import com.moli.lumpSugar.common.domain.enums.YesOrNoEnum;
import com.moli.lumpSugar.common.domain.vo.request.CursorPageBaseReq;
import com.moli.lumpSugar.common.domain.vo.response.CursorPageBaseResp;
import com.moli.lumpSugar.common.utils.CursorUtils;
import com.moli.lumpSugar.user.domain.entity.UserFriend;
import com.moli.lumpSugar.user.mapper.UserFriendMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: LumpSugarChat
 * @description:
 * @author: zhangjt
 * @create: 2024-10-30 09:08
 **/
@Service
public class UserFriendDao extends ServiceImpl<UserFriendMapper, UserFriend> {
    public CursorPageBaseResp<UserFriend> friendList(Long uid, CursorPageBaseReq request) {
        return CursorUtils.getCursorPageByMysql(this, request, wrapper -> wrapper.eq(UserFriend::getUid, uid), UserFriend::getId);
    }

    public UserFriend checkFriendIsHave(Long uid, Long targetUid) {
        return lambdaQuery().eq(UserFriend::getUid,uid)
                .eq(UserFriend::getFriendUid,targetUid)
                .eq(UserFriend::getDeleteStatus, YesOrNoEnum.NO.getStatus())
                .one();
    }

    public List<UserFriend> check(Long uid, List<Long> uidList) {
        return lambdaQuery().eq(UserFriend::getUid,uid)
                .in(UserFriend::getFriendUid,uidList)
                .eq(UserFriend::getDeleteStatus,YesOrNoEnum.NO.getStatus())
                .list();
    }

    public List<UserFriend> getUserFriend(Long uid, Long targetUid) {
        return lambdaQuery().eq(UserFriend::getUid, uid)
                .eq(UserFriend::getFriendUid,targetUid)
                .eq(UserFriend::getDeleteStatus,YesOrNoEnum.NO.getStatus())
                .or()
                .eq(UserFriend::getUid,targetUid)
                .eq(UserFriend::getFriendUid,uid)
                .eq(UserFriend::getDeleteStatus,YesOrNoEnum.NO.getStatus())
                .select(UserFriend::getId)
                .list();
    }
}
